package com.whitedust.top30;

import java.util.HashMap;
import java.util.Map;

/**
 * @author A
 * @since 2025/11/3 19:15
 */

public class Top27 {

    public String addStrings(String num1, String num2) {
        char[] charArray1 = num1.toCharArray();
        char[] charArray2 = num2.toCharArray();
        int i = num1.length() - 1;
        int j = num2.length() - 1;
        int add = 0;
        StringBuffer sb = new StringBuffer();
        //最高位相加后如果进位不为零的情况也需要考虑
        while (i >= 0 || j >= 0 || add != 0) {
            //全部数位都要进行相加
            int tmp1 = i >= 0 ? charArray1[i] - '0' : 0;
            int tmp2 = j >= 0 ? charArray2[j] - '0' : 0;
            int sum = tmp1 + tmp2 + add;
            add = sum / 10;
            sb.append(sum % 10);
            i--;
            j--;
        }
        return sb.reverse().toString();
    }
}
